<template>
	<view class="index">
		<view class="search-wrapper">
			<input type="text" v-model="keywords" class="input" placeholder="输入商品名称、客户名称" @confirm="search"
				confirm-type="search" />
			<uni-icons v-if="keywords" type="clear" @tap="keywords = ''" size="18" color="#898989"
				class="close"></uni-icons>
			<image src="https://cdpresources.hobon.cc/procurement-mini-program/static/search.png" class="icon"
				mode="widthFix"></image>
			<view class="search-btn" @click="search">
				搜索
			</view>
		</view>
		<view class="tabs-wrapper">
			<v-tabs v-model="current" @change="changeTab" :tabNumbers="tabNumbers" :tabs="tabList" :scroll="false"
				:bold="false" lineHeight="4rpx" lineColor="#F26022" activeColor="#F26022" color="#79838A"
				fontSize="30rpx"></v-tabs>
		</view>
		<view class="page-wrapper">
			<swiper class="swiper" :current="current" @change="changePage">
				<swiper-item class="swiper-item" v-for="(_swiper,i) in tabList" :key="i">
					<mescroll-item ref="mescrollItem" @getCount="getCount" @refresh="search" :keywords="keywords" :i="i"
						:index="current"></mescroll-item>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import MescrollItem from "./mescroll-swiper-item.vue";

	export default {
		data() {
			return {
				orderType: 0,
				tabList: ['全部', '运输中', '待自提', '待配送', '已交付'],
				first: true,
				current: 0,
				keywords: '',
				tabNumbers: []
			}
		},
		onLoad(option) {
			this.getCount()
			if (option.type == 2) {
				this.changePage({
					detail: {
						current: 2
					}
				})
			} else if (option.type == 3) {
				this.changePage({
					detail: {
						current: 3
					}
				})
			}
		},
		onShow() {
			//this.search()
		},
		methods: {
			changePage(e) {
				this.current = e.detail.current;
			},
			changeTab() {

			},
			search() {
				this.getCount();
				this.$refs.mescrollItem[this.current].refresh();
			},
			async getCount() {
				const data = await this.$api.post('/app/deliver/order/statusCount', {
					pickupPointId: this.$store.state.userInfo.pickupPointId
				}, false)
				if (data.code === 200) {
					this.tabNumbers = [0, data.data.coming, data.data.pickup, data.data.delivery, 0]
				}
			}
		},
		components: {
			MescrollItem
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: hidden;

		.search-wrapper {
			background-color: #ffffff;
			margin: 3upx 0;
			padding: 10upx 20upx;
			position: relative;
			display: flex;
			align-items: center;

			.input {
				border-radius: 10upx;
				border: 2upx solid #acacac;
				height: 70upx;
				width: 100%;
				padding: 0 120upx 0 30upx;
				box-sizing: border-box;
				font-size: 32upx;
			}

			.icon {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				right: 190upx;
				width: 26upx;
				height: 26upx;
			}

			.close {
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				right: 230upx;
			}

			.search-btn {
				width: 200upx;
				background-color: #F26022;
				color: #ffffff;
				height: 70upx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10upx;
				margin-left: 10upx;
				font-size: 28upx;
			}
		}

		.swiper {
			height: calc(100vh - 70upx);

			.nodata-wrapper {
				text-align: center;
				font-size: 32upx;
				color: #666666;

				.nodata-image {
					margin-top: 300upx;
					margin-bottom: 10upx;
					width: 246upx;
				}

				.loading-image {
					margin-top: 300upx;
					margin-bottom: 10upx;
					width: 296upx;
					height: 205upx;
				}
			}
		}
	}
</style>